<form class="layui-form" action="" id="updateUserPwdForm" lay-filter ="updateUserPwdForm" style="padding:40px">
    <input type="hidden" name="uId" id="userId"/>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">原密码:</label>
            <div class="layui-input-inline">
                <input type="text" name="nowUserPwd" id="nowUserPwdId" required lay-verify="required" placeholder="请输入原密码" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">新密码:</label>
            <div class="layui-input-inline">
                <input type="password" name="newUserPwd" required lay-verify="required" placeholder="请输入新密码" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">新密码:</label>
            <div class="layui-input-inline">
                <input type="password" name="userPwd" id="userpwdId" required lay-verify="required" placeholder="请再次输入新密码" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="padding-top:20px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="UpdateUserPwdFormBtn">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    //定义一个当前登陆用户的密码变量
    var nowUserPwdValue = "";
    var nowUserPwdFormValue ="";
    var newUserPwdFormValue = "";
    var userPwdFormValue = "";

    //初始化页面
    $(function () {
        //用户ID全局变量为userid
        nowUserPwdValue = myuser.userPwd;
        $('#userId').val(userid);

    });

    form.on('submit(UpdateUserPwdFormBtn)',function (data) {
        nowUserPwdFormValue = data.field.nowUserPwd;
        newUserPwdFormValue = data.field.newUserPwd;
        userPwdFormValue = data.field.userPwd;
        //判断密码
        if(nowUserPwdValue!=nowUserPwdFormValue) {
            layer.msg('原密码有错误');
        }else if(newUserPwdFormValue!=userPwdFormValue) {
            layer.msg('新密码有错误');
        }else{
            $.getJSON("/updateUserPwdByUserId", data.field, function (data) {
                //添加成功
                layer.msg(data.msg);
                //人员信息添加成功后刷新当前表单页面
                if (data.msg.indexOf('成功') > -1) {
                    //刷新当前表单
                    $('#updateUserPwdForm')[0].reset();
                    //关闭弹出窗体。
                    layer.close(openLayId);
                    //退出到登录页面
                    layer.confirm('您已成功修改密码，将要退回登录页面噢！！！', {
                        btn: ['确定'] //按钮
                        ,btnAlign: 'c' //按钮居中
                    }, function() {
                        userLoginOut();
                    });
                }
            });
            }
        return false;
    });
</script>